package com.jgzx.domain;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author jackesy
 * @className: PageVO
 * @description: 分页响应VO
 * @create 2020/9/10 17:41
 **/
@Data
public class PageVO<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 总记录数
     */
    @ApiModelProperty(value = "总记录数")
    private Long total_count = 0L;

    /**
     * 总页数
     */
    @ApiModelProperty(value = "总页数")
    private Long total_page = 0L;

    /**
     * 查询结果集
     */
    @ApiModelProperty(value = "结果集合")
    private List<T> records = new ArrayList<>();

    /**
     * 拓展参数
     */
    @ApiModelProperty(value = "拓展参数")
    private Map<String, Object> map = new HashMap<>();

    public void setRecords(List<T> records) {
        if (records != null && records.size() > 0) {
            this.records = records;
        }
    }

    public PageVO(Long total_count, Long total_page) {
        this.total_count = total_count;
        this.total_page = total_page;
    }

    public PageVO(Long total_count, Long total_page, List<T> records) {
        this.total_count = total_count;
        this.total_page = total_page;
        if (records != null && records.size() > 0) {
            this.records = records;
        }
    }

    public PageVO(Long total_count, Long total_page, List<T> records, Map<String, Object> map) {
        this.total_count = total_count;
        this.total_page = total_page;
        if (records != null && records.size() > 0) {
            this.records = records;
        }
        if (map != null) {
            this.map = map;
        }
    }
}
